/**
 * 消费能力管理初始化
 */
var MsgSendLog = {
    id: "MsgSendLogTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
MsgSendLog.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '', field: 'id', visible: false, align: 'center', valign: 'middle', width: '50px'},
        {title: '发送人', field: 'sender', align: 'center', valign: 'middle', sortable: true},
        {title: '门诊', field: 'outpatientName', align: 'center', valign: 'middle', sortable: true},
        {title: '患者电话', field: 'customerPhone', align: 'center', valign: 'middle', sortable: true},
        {title: '患者姓名', field: 'customerName', align: 'center', valign: 'middle', sortable: true},
        {
            title: '发送时间', field: 'sendTime', align: 'center', valign: 'middle', sortable: true,
            formatter: function (value, row, index) {
                return value.substring(0, 19);
            }
        },
        {title: '短信内容', field: 'messageContent', align: 'center', valign: 'middle', sortable: true},
        {
            title: '是否成功', field: 'isSuccess', align: 'center', valign: 'middle', sortable: true,
            formatter: function (value, row, index) {
                if (value == 1) {
                    return "发送成功";
                } else {
                    return "发送失败";
                }
            }
        },
    ];
};

/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
MsgSendLog.formParams = function () {
    var queryData = {};
    queryData['sender'] = $("#sender").val();
    queryData['customerPhone'] = $("#customerPhone").val();
    queryData['customerName'] = $("#customerName").val();
    queryData['startTime'] = $("#startTime").val();
    queryData['endTime'] = $("#endTime").val();
    queryData['outpatientName'] = $("#outpatientName").val();
    return queryData;
}

MsgSendLog.resetSearch = function () {
    $("#sender").val("");
    $("#customerPhone").val("");
    $("#customerName").val("");
    $("#startTime").val("");
    $("#endTime").val("");
    $("#outpatientName").val("");
    MsgSendLog.search();
};

/**
 * 查询列表
 */
MsgSendLog.search = function () {
    MsgSendLog.table.refresh({query: MsgSendLog.formParams()});
};

$(function () {
    //初始化下拉到店门诊列表
    $.post(Feng.ctxPath + "/outpatientManagement/getList", function (data) {
        var txt = '<option value="">--请选择到店门诊--</option>';
        for (var i = 0; i < data.length; i++) {
            txt += '<option value="' + data[i].simplename + '">' + data[i].simplename + '</option>';
        }
        document.getElementById('outpatientName').innerHTML = txt;
        //状态单选
        var seleteooutpatientName = $('#outpatientNameValue').val();
        if (seleteooutpatientName != "") {
            $("#outpatientName option[value=" + seleteooutpatientName + "]").attr("selected", "selected");
        }
    }, "json");
    var defaultColunms = MsgSendLog.initColumn();
    var table = new BSTable(MsgSendLog.id, "/msgSendLog/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(MsgSendLog.formParams());
    MsgSendLog.table = table.init();
});
